﻿using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace CustomWindows.Window_API
{
    class Hotkeys
    {
        /// <summary>
        /// Typical hotkey assigngments
        /// </summary>
        public enum WindowKeys
        {
            Alt = 0x0001,
            Control = 0x0002,
            Shift = 0x0004, // Changes!
            Window = 0x0008,
        }

		#region Fields (1) 

        private readonly IntPtr _hwnd;

		#endregion Fields 

		#region Constructors (1) 

        public Hotkeys(IntPtr hwnd)
        {
            _hwnd = hwnd;
        }

		#endregion Constructors 

		#region Methods (2) 

		// Public Methods (2) 

        public void RegisterHotkeys()
        {
            RegisterHotKey(_hwnd, 1, (int)WindowKeys.Control, (int)Keys.A); //Ctrl + A top
            RegisterHotKey(_hwnd, 2, (int)WindowKeys.Control, (int)Keys.M); //Ctrl + M will be max
            RegisterHotKey(_hwnd, 3, (int)WindowKeys.Control, (int)Keys.T); //Ctrl + T
            RegisterHotKey(_hwnd, 4, (int)WindowKeys.Shift, (int)Keys.Left);
            RegisterHotKey(_hwnd, 5, (int)WindowKeys.Shift, (int)Keys.Right);
        }

        public void UnregisterHotKeys()
        {
            UnregisterHotKey(_hwnd, 1);
            UnregisterHotKey(_hwnd, 2);
            UnregisterHotKey(_hwnd, 3);
            UnregisterHotKey(_hwnd, 4);
            UnregisterHotKey(_hwnd, 5);
        }

		#endregion Methods 

        #region API
        [DllImport("user32.dll")]
        private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
        [DllImport("user32.dll")]
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
        #endregion
    }
}
